<?php
class AdminDocumentForm extends VTNSDocumentForm
{	
	public function configure()
    {
		$cms = $this->getDefaults();
		$this->setWidgets(array(
                'name'                			=> new sfWidgetFormInput(),
				'document_category_id'			=> new SfWidgetFormChoice(array('choices' => $this->getdocumentCategory())),
				'file'           			    => new sfWidgetFormInputFile(),
				'description'          			=> new sfWidgetFormTextarea(),
				'content'           			=> new sfWidgetFormTextarea(),
				'is_active'						=> new sfWidgetFormInputCheckbox(),
				));
		$this->setValidators(array(
	            'name'           		    	=>  new sfValidatorString(array('required' => false)),
	            'description'                	=>  new sfValidatorString(array('required' => false))
		));
        $this->widgetSchema->setNameFormat('document[%s]');
		$this->widgetSchema->setLabels(array(
				'name'							=> 'Tiêu đề',
				'document_category_id'			=> 'Danh mục',
				'file'  						=> 'Tài liệu',
				'description'					=> 'Mô tả',
				'content'						=> 'Nội dung',
				'is_active'						=> 'Kích hoạt',
		));
	}
	
	private function getdocumentCategory()
	{
        $document_category = array();	   
        $c = Doctrine_Query::create()
			->select('c.*')
			->from('VtnsDocumentCategory c')
			->orderBy('c.position');
        $results = $c->execute();
		foreach ($results as $result)
			$document_category[$result->document_category_id] = $result->name;
		return $document_category;
	}
}
?>